#include "stdafx.h"

void demoslice :: init()
{
    zero = 0;
    FOR(80)
        ages[i] = 10;
    run_sim = true;
    bar_ratio = 1.f;
}

void demoslice :: step()
{
    zero++;
    zero %= 80;
    repr = (zero + 26) % 80;

    ages[zero] = long(float(ages[repr]) * 1.25f);

}

void demoslice:: update_bars()
{
    FOR(80)
        while(float(ages[i])*bar_ratio * float(BAR_H_MAX) > float(BAR_H_MAX))
            bar_ratio *= 0.5f;
    ostringstream oss;

    FOR(AGE_MAX)
        bars[i].setSize(
            sf::Vector2f(BAR_WIDTH,
                - float(BAR_H_MAX) * bar_ratio * float(ages[i])
                ));

    //oss
    //     << "\n bar_ratio: "      << bar_ratio
    //     << "\n born per year: "  << births_this_year
    //     << "\n able people: "    << reproducing_people
    //     << "\n inhabitants: "    << pop.size()
    //     << "\n births total: "   << births_total << "\n";
    text.setString(oss.str());
    
}

void demoslice :: init_bars()
{
    text = sf::Text("",sf::Font::getDefaultFont(),FONT_SIZE);
    text.setPosition(30,0);
    FOR(80)
        bars[i].setPosition(BAR_WIDTH*i, BAR_H_MAX);
        //bars[i].setSize(Vector2f(float(BAR_WIDTH), float(BAR_H_MAX)));

    FOR2(0, AGE_REPRODUCE_MIN)                  bars[i].setFillColor(sf::Color(128,0,0));//::Cyan);
    FOR2(AGE_REPRODUCE_MIN, AGE_REPRODUCE_MAX)  bars[i].setFillColor(sf::Color(0,128,0));//::Green);
    FOR2(AGE_REPRODUCE_MAX,AGE_MAX)             bars[i].setFillColor(sf::Color(0,0,128));//::Yellow);
}
